﻿@section header{
    <style>
    </style>
}

<div class="ui-layout-west" style="float:left;height: 100%; width: 15%;overflow-y:scroll;">
    <input id="zTreesso" name="zTreesso" type="text" style="width:100%;height:25px;" placeholder="请输入关键字" />
    <ul id="itemTree" class="ztree"></ul>
</div>
<div style="height: 100%; width: 85%;float:left;overflow-y:scroll;">
    <partial name="_page_list" />
</div>

@section scripts{
    <script>
        var baseUrl = "/rbac/User/";
        var treeNodeId = "";
        $(function () {
            bindPersonAC();
            $(".toolbar .fr").append('<a id="NF-btn_userrole" authorize="yes" class="btn btn-primary " onclick="btn_userrole()"><i class="glyphicon glyphicon-user"></i>&nbsp;赋予角色</a>');
            $(".toolbar .fr").append('<a id="NF-btn_userrole" authorize="yes" class="btn btn-primary " onclick="btn_resetpassword()"><i class="glyphicon glyphicon-user"></i>&nbsp;重置密码</a>');
            treeView();
            gridList();
        })
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                url: baseUrl + "GetJGridPageDataJson",
                datatype: "json",
                height: $(window).height() - 228,
                mtype: "POST",
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true },
                    {
                        label: '排序', name: 'OrderBy', width: 100, align: 'center', frozen: true,
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return "<input type='text' name='OrderBy[" + keyId + "]' autocomplete='off' style='width: 50px; height: 20px;' onchange='update_field(\"" + keyId + "\",this.value)' value=" + cellvalue + " />";
                        }
                    },
                    { label: '登录帐号', name: 'Account', width: 100, align: 'left', frozen: true },
                    { label: '用户姓名', name: 'Name', width: 100, align: 'left', frozen: true },
                    { label: '用户性别', name: 'Sex', width: 50, align: 'left' },
                    {
                        label: "用户状态", name: "Status", align: "center", width: 100,
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return cellvalue == 0 ? "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-on\"></i>" : "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: '用户手机', name: 'Mobile', width: 100, align: 'left' },
                    { label: '电子邮箱', name: 'Email', width: 120, align: 'left' },
                    { label: '证件类型', name: 'IdcardType', width: 80, align: 'left' },
                    { label: '证件号码', name: 'Idcard', width: 120, align: 'left' },
                    { label: '国籍地区', name: 'Nationality', width: 100, align: 'center' },
                    {
                        label: '宗教信仰', name: 'Faith', align: 'left', width: 100,
                        formatter: function (cellvalue) {
                            try {
                                return top.clients.dataItems["ZJXY"][cellvalue] == undefined ? "" :
                                    top.clients.dataItems["ZJXY"][cellvalue]
                            } catch (err) {
                                return "";
                            }
                        }
                    },
                    {
                        label: '健康状况', name: 'Health', align: 'left', width: 100,
                        formatter: function (cellvalue) {
                            try {
                                return top.clients.dataItems["JKZK"][cellvalue] == undefined ? "" :
                                    top.clients.dataItems["JKZK"][cellvalue]
                            } catch (err) {
                                return "";
                            }

                        }
                    },
                    {
                        label: '婚姻状态', name: 'Marry', align: 'left', width: 100,
                        formatter: function (cellvalue) {
                            try {
                                return top.clients.dataItems["HYZT"][cellvalue] == undefined ? "" :
                                    top.clients.dataItems["HYZT"][cellvalue]
                            } catch (err) {
                                return "";
                            }
                        }
                    },
                    {
                        label: '政治面貌', name: 'PoliticalID', align: 'left', width: 100,
                        formatter: function (cellvalue) {
                            try {
                                return top.clients.dataItems["ZZMM"][cellvalue] == undefined ? "" :
                                    top.clients.dataItems["ZZMM"][cellvalue]
                            } catch (err) {
                                return "";
                            }
                        }
                    },
                    { label: '生肖', name: 'Zodiac', width: 100, align: 'left' },
                    { label: '星座', name: 'Constellation', width: 100, align: 'left' },
                    {
                        label: '出生日期', name: 'BirthDate', width: 120, align: 'left',
                        formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                    },
                    { label: '名族', name: 'NationalID', width: 100, align: 'left' },
                    { label: '籍贯', name: 'NativePlace', width: 100, align: 'left' },
                    { label: '邮寄地址', name: 'Address', width: 100, align: 'left' },
                    { label: '邮编', name: 'Zipcode', width: 100, align: 'left' },
                    { label: '添加时间', name: 'AddTime', width: 120, align: 'center' }
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'ID',
                sortorder: "asc",
                viewrecords: true,
                autowidth: true,
                multiselect: true
            });
            $("#btn_search").click(function () {
                var param = {
                    key: $("#txt_keyword").val(),
                    OrgId: treeNodeId
                }
                $gridList.jqGrid('setGridParam', {
                    postData: { keyword: JSON.stringify(param) },
                }).trigger('reloadGrid');
            });
        }
        function btn_add() {
            $.modalOpen({
                id: "Form",
                title: "新增",
                url: baseUrl + "Form",
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_edit(id) {
            if (id == "" || id == undefined) {
                var ids = get_gridId("gridList");
                console.log(ids);
                if (ids == "" || ids == undefined) {
                    $.modalAlert("请选择一条数据", "warning");
                    return;
                }
                if (ids.length > 1) {
                    $.modalAlert("不能选择多条数据", "warning");
                    return;
                }
                id = ids[0];
            }
            $.modalOpen({
                id: "Form",
                title: "修改",
                url: pageUrl + "Form?keyValue=" + id,
                width: "600px",
                height: "800px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_delete(id) {
            if (id == "" || id == undefined) {
                var ids = get_gridId("gridList");
                if (ids == "" || ids == undefined) {
                    $.modalAlert("请选择一条数据", "warning");
                    return;
                }
                id = ids;
            }
            $.deleteForm({
                url: pageUrl + "DeleteForm",
                param: { keyValue: id },
                success: function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_userrole(id) {
            if (id == "" || id == undefined) {
                var ids = get_gridId("gridList");
                if (!!ids) {
                    id = ids;
                } else {
                    $.modalAlert("请选择一条数据", "warning");
                    return;
                }
            }
            console.log(id);
            $.modalOpen({
                id: "UserRole",
                title: "赋予角色",
                url: baseUrl + "UserRole?keyValue=" + id,
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_resetpassword(id) {
            if (id == "" || id == undefined) {
                var ids = get_gridId("gridList");
                if (ids == "" || ids == undefined) {
                    $.modalAlert("请选择一条数据", "warning");
                    return;
                }
                id = ids;
            }
            $.deleteForm({
                prompt: "注：您确定要重置该用户密码吗？",
                loading: "正在重置密码...",
                url: baseUrl + "ResetPassword",
                param: { keyValue: id },
                success: function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        //关闭有效触发
        function Switch(keyId) {
            $.ajax({
                url: baseUrl + "Switch?keyId=" + keyId,
                data: {},
                type: "POST",
                dataType: "json",
                async: false,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
        function update_field(keyId, cellvalue) {
            $.ajax({
                url: baseUrl + "UpdateOrderBy?keyId=" + keyId + "&value=" + cellvalue,
                data: {},
                dataType: "json",
                type: "POST",
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }

        function treeView() {
            var setting = {
                view: {
                    dblClickExpand: false,
                    showLine: true,
                    selectedMulti: false
                },
                data: {
                    key: {
                        name: "Name",
                    },
                    simpleData: {
                        enable: true,
                        idKey: "ID",
                        pIdKey: "ParentID",
                        rootPId: ""
                    }
                },
                callback: {
                    // 单击事件
                    onClick: function zTreeOnClick(event, treeId, treeNode) {
                        treeNodeId = treeNode.ID;
                        $("#txt_keyword").val('');
                        $('#btn_search').trigger("click");
                    }
                }
            };
            $.ajax({
                url: "/rbac/Organize/GetAll",
                type: "post",
                dataType: "json",
                success: function (data) {
                    var zTreeObj = $.fn.zTree.init($("#itemTree"), setting, data);
                    fuzzySearch('itemTree', '#zTreesso', null, true); //初始化模糊搜索方法
                }
            });
        }
    </script>
}
